import React, { Component } from 'react'
import {baseUrl,dcomment} from '../../../api/base'
import Detailpjitem from '../detailpjitem/detailpjitem'
import Loadmore from '../../../components/loadmore/loadmore'
export default class Detailspj extends Component {
    state={
        hasMore:false,
        list:[],
        page:0
    }
    componentDidMount(){
        document.documentElement.scrollTop=0;
       this.getdata()
    }
    getdata=(fn)=>{
        fetch(baseUrl+dcomment+"?id="+this.props.id+'&page'+this.state.page)
        .then(res=>res.json())
        .then(res=>{
            console.log(res)
            this.setState({
                hasMore:res.hasMore,
                list:[...res.data,...this.state.list],
                page:this.state.page+1
            })
            if(fn){
                fn(true)
            }
        })
    }
    render() {
        return (
            <div>
                {this.state.list.map((v,i)=>{
                    return <Detailpjitem key={i} data={v}/>
                })}
                {/* //加载更多 */}
                {
                    this.state.hasMore
                    ?
                    <Loadmore getdata={this.getdata}/>
                    :
                    <div>我是有底线的....</div>
                }
                {/* <Loadmore getdata={this.getdata}/> */}
                
            </div>
        )
    }
}
